<template>
  <div class="_wz_cent_main _wz_tryingStudyAdd">

    <Form label-position="right" :label-width="100" ref="formAdd" :model="formData" :rules="ruleValidate">
      <FormItem label="隐患项目" prop="riskPositionItemName">
        <i-input v-model="formData.riskPositionItemName" placeholder="请填写隐患项目" clearable />
      </FormItem>
      <FormItem label="责任部门" prop="riskPositionItemInOrgUuid">
        <i-select v-model="formData.riskPositionItemInOrgUuid" placeholder="请选择责任部门" clearable @on-change="departmentalAl">
          <Option v-for="item in departmentList" :value="item.uuid" :key="item.uuid">{{ item.inOrgName }}</Option>
        </i-select>
      </FormItem>
      <FormItem label="责任人" prop="riskPositionItemUserUuid">
        <i-select v-model="formData.riskPositionItemUserUuid" placeholder="请选择责任人" clearable>
          <Option v-for="item in systemUserPageList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
        </i-select>
      </FormItem>
      <FormItem label="检查标准" prop="riskPositionItemCriterion">
        <i-input v-model="formData.riskPositionItemCriterion" type="textarea" :rows="4" placeholder="请填写检查标准" clearable />
      </FormItem>
      <FormItem label="失控表现" prop="riskPositionItemPerformance">
        <i-input v-model="formData.riskPositionItemPerformance" type="textarea" :rows="4" placeholder="请填写失控表现" clearable />
      </FormItem>
      <FormItem label="管控措施" prop="riskPositionItemMeasures">
        <i-input v-model="formData.riskPositionItemMeasures" type="textarea" :rows="4" placeholder="请填写管控措施" clearable />
      </FormItem>
      <FormItem label="个人防护" prop="riskPositionItemProtect">
        <i-input v-model="formData.riskPositionItemProtect" type="textarea" :rows="4" placeholder="请填写个人防护" clearable />
      </FormItem>
      <FormItem label="应急措施" prop="riskPositionItemBurst">
        <i-input v-model="formData.riskPositionItemBurst" type="textarea" :rows="4" placeholder="请填写应急措施" clearable />
      </FormItem>

    </Form>
    <div class="demo-drawer-footer">
      <Button style="margin-right: 8px" @click="$emit('closeFun', false)">取消</Button>
      <Button type="primary" @click="authSubmit('formAdd')">提交</Button>
    </div>

    <Spin size="large" fix v-if="spinShow"></Spin>
  </div>
</template>
<script>

export default {
  props: ["selectData",'selectDataParent'],
  data: function () {
    return {
      systemUserPageList:[],//人员list
      departmentList:[],//部门list
      spinShow: false,//本页加载
      ruleValidate: {
        riskPositionItemName: [
          {required: true, message: '请填写隐患项目', trigger: 'blur'},
        ],
        riskPositionItemInOrgUuid: [
          {required: true, message: '请选择责任部门', trigger: 'blur'},
        ],
        riskPositionItemUserUuid: [
          {required: true, message: '请选择责任人', trigger: 'blur'},
        ],
        riskPositionItemCriterion: [
          {required: true, message: '请填写检查标准', trigger: 'blur'},
        ],
        riskPositionItemPerformance: [
          {required: true, message: '请填写失控表现', trigger: 'blur'},
        ],
        riskPositionItemMeasures: [
          {required: true, message: '请填写管控措施', trigger: 'blur'},
        ],
        riskPositionItemProtect: [
          {required: true, message: '请填写个人防护', trigger: 'blur'},
        ],
        riskPositionItemBurst: [
          {required: true, message: '请填写应急措施', trigger: 'blur'},
        ],
      },
      formData:{},
    }
  },
  beforeCreate() {//beforeCreate创建前状态
  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程
  },
  mounted() {//mounted 挂载结束状态
    var that = this;
    that.formData = that.selectData;
    that.departmentalAl()

    //部门
    that.axios.post(that.apiUrl.coreInOrgCoreInOrgList,{deptUuid:that.selectDataParent.deptUuid}).then(res => {
      if (!!res) {
        that.departmentList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })

  },
  methods: {//执行的方法
    //部门级联
    departmentalAl(){
      let that = this;
      if(!!that.formData.riskPositionItemInOrgUuid){
        that.axios.post(that.apiUrl.systemUserSystemUserList,{inOrgUuid:that.formData.riskPositionItemInOrgUuid}).then(res => {
          if (!!res) {
            that.systemUserPageList = res.data.data;
            if(that.systemUserPageList.length == 0){
              that.$set(that.formData, 'riskPositionItemUserUuid', '');//赋值
            }
          }
        }).catch(err => {
          console.log("失败", err)
        })
      }else{
        that.systemUserPageList = [];
        that.$set(that.formData, 'riskPositionItemUserUuid', '');//赋值
      }
    },

    authSubmit(name) {
      var that = this;
      that.$refs[name].validate((valid) => {
        if (valid) {//正则判断使用
          that.formData.riskPositionUuid = that.selectDataParent.uuid;//排查位置id

          that.spinShow = true;
          that.axios.post(that.apiUrl.webApi + "/risk/position/riskPositionItemSaveOrUpdate", that.formData).then(res => {
            that.spinShow = false;
            if (!!res) {
              that.$emit("closeFun", true)
              that.$Message.success('保存成功')

            }
          }).catch(err => {
            console.log("失败", err)
          })

        } else {
          this.$Message.error('请正确填写表单');
        }
      })

    },
  },
  watch: {//监听
  },
  beforeUpdate() {//beforeUpdate 更新前状态
  },
  updated() {//updated 更新完成状态
  },
  beforeDestroy() {//beforeDestroy 销毁前状态
  },
  destroyed() {//destroyed 销毁完成状态
  }
}
</script>


<style lang="less">
._wz_tryingStudyAdd {

}

</style>


